<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增住院管理')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-hospitalized-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">患者姓名：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="patientId" name="patientId" type="hidden"/>
                    <input class="form-control" type="text" onclick="selectPatientIdRadio()" id="patientName"
                           readonly="true" th:value="${patientName}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">科室名称：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="departmentId" name="departmentId" type="hidden" th:value="${departmentId}"/>
                    <input class="form-control" type="text" onclick="selectDepartmentIdRadio()" id="departmentName"
                           readonly="true" th:value="${departmentName}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">医生姓名：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="doctorId" name="doctorId" type="hidden" th:value="${doctorId}"/>
                    <input class="form-control" type="text" onclick="selectDoctorIdRadio()" id="doctorName"
                           readonly="true" th:value="${doctorName}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">入院日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="admissionDate" class="form-control layui-datetime" placeholder="yyyy-MM-dd HH:mm:ss"
                           type="text" required>
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">床位：</label>
            <div class="col-sm-8">
                <input name="bunk" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var prefix = ctx + "hospital/hospitalized"
    var patientPrex = ctx + "hospital/patient"
    var deptPrefix = ctx+"hospital/department"
    var doctorPrefix = ctx+"hospital/doctor"
    $("#form-hospitalized-add").validate({
        focusCleanup: true
    });

    function selectPatientIdRadio(){
        var options = {
            title: '选择患者',
            url: patientPrex+"/selectPatient",
            callBack: doPatientSubmit
        };
        $.modal.openOptions(options);
    }

    function doPatientSubmit(index,layer){
        var body = $.modal.getChildFrame(index);
        $("#patientId").val(body.find("#patientId").val());
        $("#patientName").val(body.find("#patientName").val());
        $.modal.close(index);
    }

    function selectDepartmentIdRadio(){
        var options = {
            title: '选择科室',
            url: deptPrefix+"/selectDepartment",
            callBack: doDepartmentSubmit
        };
        $.modal.openOptions(options);
    }

    function doDepartmentSubmit(index,layer){
        var body = $.modal.getChildFrame(index);
        $("#departmentId").val(body.find("#departmentId").val());
        $("#departmentName").val(body.find("#departmentName").val());
        $.modal.close(index);
    }

    function selectDoctorIdRadio(){
        var options = {
            title: '选择医师',
            url: doctorPrefix+"/selectDoctor?type=hospitalization",
            callBack: doDoctorSubmit
        };
        $.modal.openOptions(options);
    }

    function doDoctorSubmit(index,layer){
        var body = $.modal.getChildFrame(index);
        $("#doctorId").val(body.find("#doctorId").val());
        $("#doctorName").val(body.find("#doctorName").val());
        $.modal.close(index);
    }


    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-hospitalized-add').serialize());
        }
    }
</script>
</body>
</html>